﻿using System.ComponentModel;
using System.Data;
using System.Windows;
namespace WPFExcelReport
{
    public partial class TUMENU
    {

        public TUMENU()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VICC_MENUDEF();
            this.DataContext = MV;
            InitializeComponent();
        }
        public override void QueryCommand(object sender, RoutedEventArgs e)
        {
            dwData = TBMain.NewRow();
            SResult = ((VICC_MENUDEF)MV).QueryICC_MENUDEF(dwData, 9999);
            MergeData(SResult, false);
            base.QueryCommand(sender, e);
        }
        public override void NewCommand(object sender, RoutedEventArgs e)
        {
            dwData = TBMain.NewRow();
            TMV.SetUpNewRow(ref dwData);
            LFD = VSDDAT.SD22.GETNEXT("0022", "  ", "MUSEQ", 1);
            dwData["ROWNID"] = LFD;
            //dwData["USERID"] = USERID;
            TMV.DeleteICC_MENUDEF(dwData, 2);
            TMV.InsertICC_MENUDEF(dwData, app.company);
            TBMain.Rows.InsertAt(dwData, 0);
            vwMaster.View.MoveCurrentToFirst();
            base.NewCommand(sender, e);
        }
        
        public override void DeleteCommand(object sender, RoutedEventArgs e)
        {
            if (dwMaster == null)
                return;
            TMV.DeleteICC_MENUDEF(dwMaster, 2);
            filter = "ROWNID='" + dwMaster["ROWNID"].ToString() + "'";
            rows = TBMain.Select(filter);
            vwMaster.View.MoveCurrentTo(-1);
            foreach (DataRow row in rows)
            {
                row.Delete();
            }
            TBMain.AcceptChanges();
            base.DeleteCommand(sender, e);
        }
        public override void CopyCommand(object sender, RoutedEventArgs e)
        {
            if (dwMaster == null)
                return;
            dwData = TBMain.NewRow();
            dwData.ItemArray = dwMaster.ItemArray;
            LFD = VSDDAT.SD22.GETNEXT("0022", "  ", "MUSEQ", 1);
            dwData["ROWNID"] = LFD;
            TMV.DeleteICC_MENUDEF(dwData, 2);
            TMV.InsertICC_MENUDEF(dwData, app.company);
            TBMain.Rows.InsertAt(dwData, 0);
            vwMaster.View.MoveCurrentToFirst();
            base.CopyCommand(sender, e);
        }
        public override void EditCommand(object sender, RoutedEventArgs e)
        {
            base.EditCommand(sender, e);
        }
        public override void OnFUNCTIONChg(DataRow dwFC)
        {
            if (dwFC == null)
                return;
            if (!IsEdit) return;
            if (dwMaster == null)
                return;
            if (MV == null)
                return;
            dwMaster["HEADER"] = dwFC["DESCRIPTION"].ToString().Trim();
            dwMaster["TAG"] = dwFC["TYPE"].ToString().Trim();
            dwMaster["MENUITEM"] = "cmd" + dwFC["TYPE"].ToString().Trim();
            base.OnFUNCTIONChg(dwFC);
        }
        public override void OnUSERIDChg(string value)
        {
            if (dwMaster == null)
                return;
            if (!IsEdit)
                return;
            if (MV == null)
                return;
            if (USERID.Length < 8)
                return;
            dwMaster["USERID"] = value.Trim().PadRight(8).Substring(0, 8);
            base.OnUSERIDChg(value);
        }
        public override void OnFNCGPChg(string value)
        {
            if (dwMaster == null)
                return;
            if (!IsEdit)
                return;
            TMV.FATHER = value;
            base.OnUSERIDChg(value);
        }
        public override void OnEXAUFChg(string vlaue)
        {
            TBMain.Clear();
            if (EXAUF.Length < 8)
                return;
            dwData = TBMain.NewRow();
            dwData["MANDANT"] = app.Mandant;
            dwData["COMPANY"] = app.company;
            dwData["USERID"] = EXAUF;
            SResult = ((VICC_MENUDEF)MV).QueryICC_MENUDEF(dwData, 2);
            MergeData(SResult, true);
            base.OnEXAUFChg(vlaue);
        }
    }
}